package dsmsforkjoin;

import java.util.LinkedList;

import tuplegenerator.Tuple;

public class SortedListQueue<T extends Tuple> implements IForkQueue<T> {

	public LinkedList<T> list = new LinkedList<T>();
	
	@Override
	public void setSize(int size) {
		// do nothing
	}

	@Override
	public int getSize() {
		return list.size();
	}

	@Override
	public void addItem(T item) {
		if (list.size() == 0 || list.getFirst() == null) {
			list.addFirst(item);
			return;
		}
		
        int j = 0;
        for (j=0; j<list.size(); j++) {
        	if (item.compareTo(list.get(j)) <= 0) {
        		break; 
        	}
        }
        
        if (j == list.size()) {
        	list.addLast(item);
        } else {
        	list.add(j, item);
        }
	}

	@Override
	public void sort() {
		// do nothing
	}

	@Override
	public T removeHead() {
		if (list.size() <= 0) return null;
		T temp = list.removeFirst();
		return temp;
	}

	@Override
	public T getItem(int index) {
		return list.get(index);
	}

	@Override
	public boolean isEmpty() {
		return (list.size() <= 0);
	}

	
	
}
